'use strict';

const conn = require('../../libs/Conn');

module.exports = async function (params) {
    /*角色判断*/
    let userSql = ``;
    if(params.is_manager !==1){
        userSql = `AND engineering_id IN (               SELECT
                                                                engineering_id
                                                            FROM
                                                                engineering_file
                                                            WHERE
                                                                principal_id = '${params.user_id}'
                                                            AND delete_sign = 1
                                                            UNION
                                                                SELECT
                                                                    efa.engineering_id
                                                                FROM
                                                                    engineering_user_middle eum
                                                                INNER JOIN engineering_file efa ON efa.engineering_id = eum.engineering_id
                                                                AND efa.delete_sign = 1
                                                                WHERE
                                                                    eum.user_id = '${params.user_id}'
                                                                UNION
                                                                    SELECT
                                                                        epid.engineering_id
                                                                    FROM
                                                                        progress_information_user_middle pium
                                                                    INNER JOIN engineering_progress_information_data epid ON epid.information_id = pium.information_id AND epid.delete_sign = 1
                                                                WHERE  pium.user_id = '${params.user_id}'
                                                            UNION
                                                                    SELECT
                                                                        engineering_id
                                                                    FROM
                                                                        engineering_progress_information_data
                                                                WHERE delete_sign = 1 AND user_id = '${params.user_id}'
                                                            ) `;
    }
    let querySql = `SELECT
                        '全部' AS dataType,
                        '0' AS value
                    
                    UNION
                        SELECT
                            engineering_name AS dataType,
                            engineering_id AS value
                        FROM
                            engineering_file 
                        WHERE
                           delete_sign = 1 ${userSql}`;
    let rec = await conn(querySql);
    return {success: true, data: rec};

};